package com.gitee.qdbp.jdbc.plugins.impl;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.gitee.qdbp.able.matches.FileMatcher;
import com.gitee.qdbp.able.matches.StringMatcher.LogicType;
import com.gitee.qdbp.able.matches.WrapFileMatcher;
import com.gitee.qdbp.tools.files.PathTools;

/**
 * SQL模板文件扫描接口的简单实现类
 *
 * @author zhaohuihua
 * @version 20200830
 * @since 3.2.0
 */
public class SimpleSqlFileScanner extends BaseSqlFileScanner {

    public SimpleSqlFileScanner() {
        super();
    }

    public SimpleSqlFileScanner(String folders, String filters) {
        super(folders, filters);
    }

    @Override
    protected List<URL> scanSqlFiles(String[] folders, String filter)  {
        FileMatcher matcher = WrapFileMatcher.parseMatchers(filter, LogicType.OR, "name", "ant", ',', '\n');
        List<URL> urls = new ArrayList<>();
        for (String item : folders) {
            List<URL> temp = PathTools.scanResources(item, matcher);
            if (temp != null && !temp.isEmpty()) {
                urls.addAll(temp);
            }
        }
        return urls;
    }
}
